/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qsdm.es.persistence;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author alberto
 */
@Entity
@Table(name = "formacion", catalog = "qsdm", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Formacion.findAll", query = "SELECT f FROM Formacion f"),
    @NamedQuery(name = "Formacion.findById", query = "SELECT f FROM Formacion f WHERE f.id = :id"),
    @NamedQuery(name = "Formacion.findByCodigo", query = "SELECT f FROM Formacion f WHERE f.codigo = :codigo"),
    @NamedQuery(name = "Formacion.findByNombre", query = "SELECT f FROM Formacion f WHERE f.nombre = :nombre")})
public class Formacion implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    private Integer id;
    @Column(name = "codigo", length = 45)
    private String codigo;
    @Column(name = "nombre", length = 512)
    private String nombre;
    @JoinColumn(name = "tipoFormacion", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Tipoformacion tipoFormacion;
    
    @JoinColumn(name = "nivelFormacion", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Nivelformacion nivelFormacion;
    
    
    public Nivelformacion getNivelFormacion() {
		return nivelFormacion;
	}

	public void setNivelFormacion(Nivelformacion nivelFormacion) {
		this.nivelFormacion = nivelFormacion;
	}

	@OneToMany(mappedBy = "formacionPadre", fetch = FetchType.LAZY)
    private List<Formacion> formacionList;
    @JoinColumn(name = "formacionPadre", referencedColumnName = "id")
    @ManyToOne(fetch = FetchType.LAZY)
    private Formacion formacionPadre;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "formacion", fetch = FetchType.LAZY)
    private List<Curso> cursoList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "formacion", fetch = FetchType.LAZY)
    private List<Usuarioformacion> usuarioformacionList;

    public Formacion() {
    }

    public Formacion(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public Tipoformacion getTipoFormacion() {
        return tipoFormacion;
    }

    public void setTipoFormacion(Tipoformacion tipoFormacion) {
        this.tipoFormacion = tipoFormacion;
    }

    @XmlTransient
    public List<Formacion> getFormacionList() {
        return formacionList;
    }

    public void setFormacionList(List<Formacion> formacionList) {
        this.formacionList = formacionList;
    }

    public Formacion getFormacionPadre() {
        return formacionPadre;
    }

    public void setFormacionPadre(Formacion formacionPadre) {
        this.formacionPadre = formacionPadre;
    }

    @XmlTransient
    public List<Curso> getCursoList() {
        return cursoList;
    }

    public void setCursoList(List<Curso> cursoList) {
        this.cursoList = cursoList;
    }

    @XmlTransient
    public List<Usuarioformacion> getUsuarioformacionList() {
        return usuarioformacionList;
    }

    public void setUsuarioformacionList(List<Usuarioformacion> usuarioformacionList) {
        this.usuarioformacionList = usuarioformacionList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Formacion)) {
            return false;
        }
        Formacion other = (Formacion) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.qsdm.es.persistence.Formacion[ id=" + id + " ]";
    }
    
}
